/*     */ package com.yc.dao.station;
/*     */ 
/*     */ import btsm.bean.dbConnector;
/*     */ import com.yc.dao.model.StoragebatteryBO;
/*     */ import com.yc.util.FormateSQL;
/*     */ import com.yc.util.ListContentsBFO;
/*     */ import java.sql.ResultSet;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.logging.Log;
/*     */ import org.apache.commons.logging.LogFactory;
/*     */ 
/*     */ public class StoragebatteryDAO
/*     */ {
/*  22 */   private static final Log log = LogFactory.getLog(StoragebatteryDAO.class);
/*     */ 
/*  24 */   private dbConnector dbcon = null;
/*  25 */   private SimpleDateFormat fresh = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
/*  26 */   private SimpleDateFormat open = new SimpleDateFormat("yyyy-MM-dd");
/*     */ 
/*     */   private void dbConInit() {
/*  29 */     if (this.dbcon == null)
/*  30 */       this.dbcon = new dbConnector();
/*     */   }
/*     */ 
/*     */   private void dbConClose() {
/*  34 */     if (this.dbcon != null)
/*  35 */       this.dbcon.closeAll();
/*  36 */     this.dbcon = null;
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getStorageBatteryList(Map condition)
/*     */   {
/*  41 */     ListContentsBFO bfo = new ListContentsBFO();
/*  42 */     int start = Integer.parseInt(condition.get("start").toString());
/*  43 */     int limit = Integer.parseInt(condition.get("limit").toString());
/*  44 */     String strBtscode = condition.get("BTS_CODE").toString();
/*  45 */     ResultSet rs = null;
/*  46 */     List list = new ArrayList();
/*     */     try
/*     */     {
/*  49 */       dbConInit();
/*  50 */       String strSQL = " select count(id) from storagebattery where btscode = '" + strBtscode + "' ";
/*  51 */       log.info(strSQL);
/*  52 */       rs = this.dbcon.execQuery(strSQL);
/*  53 */       if (rs.next()) {
/*  54 */         bfo.setTotalSize(rs.getInt(1));
/*     */       }
/*  56 */       strSQL = " select * from storagebattery where btscode ='" + strBtscode + "' limit " + start + ", " + limit;
/*  57 */       log.info(strSQL);
/*  58 */       rs = this.dbcon.execQuery(strSQL);
/*  59 */       while (rs.next()) {
/*  60 */         StoragebatteryBO bo = new StoragebatteryBO();
/*  61 */         bo.setId(rs.getString("id"));
/*     */ 
/*  63 */         bo.setBtscode(rs.getString("btscode"));
/*  64 */         bo.setNo(rs.getString("no"));
/*  65 */         bo.setSwitchNo(rs.getString("switchNo"));
/*  66 */         bo.setBtsname(rs.getString("btsname"));
/*  67 */         bo.setType(rs.getString("type"));
/*  68 */         bo.setManufacturer(rs.getString("manufacturer"));
/*  69 */         bo.setCapacity(rs.getString("capacity"));
/*  70 */         bo.setGroupnum(rs.getString("groupnum"));
/*  71 */         bo.setBatterynum(rs.getString("batterynum"));
/*  72 */         bo.setVoltage(rs.getString("voltage"));
/*  73 */         bo.setOpentime(rs.getDate("registtime"));
/*  74 */         bo.setDischarge(rs.getString("discharge"));
/*  75 */         bo.setMaintenance(rs.getString("maintenance"));
/*  76 */         bo.setRefreshtime(rs.getDate("refreshtime"));
/*  77 */         bo.setMemo(rs.getString("memo"));
/*  78 */         list.add(bo);
/*     */       }
/*  80 */       bfo.setData(list.toArray());
/*     */     }
/*     */     catch (Exception e) {
/*  83 */       e.printStackTrace();
/*  84 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/*  87 */       dbConClose();
/*     */     }
/*  89 */     return bfo;
/*     */   }
/*     */ 
/*     */   public boolean saveStoragebatteryBO(StoragebatteryBO bo)
/*     */   {
/*  94 */     log.info("添加--蓄电池---开始");
/*  95 */     boolean flag = true;
/*     */     try
/*     */     {
/*  98 */       dbConInit();
/*  99 */       StringBuffer sqlBuf = new StringBuffer();
/* 100 */       sqlBuf.append(" insert into storagebattery (  btscode,no,switchNo, btsname, type, manufacturer, capacity, groupnum,");
/* 101 */       sqlBuf.append(" batterynum,  voltage, registtime, discharge, maintenance, refreshtime,  memo ) values ( ");
/* 102 */       sqlBuf.append(" '" + bo.getBtscode() + "' ,");
/* 103 */       sqlBuf.append(" '" + bo.getNo() + "' ,");
/* 104 */       sqlBuf.append(" '" + bo.getSwitchNo() + "' ,");
/* 105 */       sqlBuf.append(" '" + bo.getBtsname() + "' ,");
/* 106 */       sqlBuf.append(" '" + bo.getType() + "' ,");
/* 107 */       sqlBuf.append(" '" + bo.getManufacturer() + "' ,");
/* 108 */       sqlBuf.append(" '" + bo.getCapacity() + "' ,");
/* 109 */       sqlBuf.append(" '" + bo.getGroupnum() + "' ,");
/* 110 */       sqlBuf.append(" '" + bo.getBatterynum() + "' ,");
/* 111 */       sqlBuf.append(" '" + bo.getVoltage() + "' ,");
/* 112 */       sqlBuf.append(" '" + this.open.format(bo.getOpentime()) + "' ,");
/* 113 */       sqlBuf.append(" '" + bo.getDischarge() + "' ,");
/* 114 */       sqlBuf.append(" '" + bo.getMaintenance() + "' ,");
/* 115 */       sqlBuf.append(" '" + this.fresh.format(new Date()) + "' ,");
/* 116 */       sqlBuf.append(" '" + bo.getMemo() + "' )");
/* 117 */       log.info(sqlBuf.toString());
/* 118 */       this.dbcon.execUpdate(sqlBuf.toString());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 122 */       flag = false;
/* 123 */       e.printStackTrace();
/* 124 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 127 */       dbConClose();
/*     */     }
/* 129 */     log.info("添加--蓄电池---结束");
/* 130 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean updateStoragebatteryBO(StoragebatteryBO bo)
/*     */   {
/* 135 */     log.info("修改--蓄电池---开始");
/* 136 */     boolean flag = true;
/*     */     try
/*     */     {
/* 139 */       dbConInit();
/* 140 */       StringBuffer sqlBuf = new StringBuffer();
/* 141 */       sqlBuf.append(" update storagebattery set ");
/* 142 */       sqlBuf.append(" no = '" + bo.getNo() + "' ,");
/* 143 */       sqlBuf.append(" switchNo = '" + bo.getSwitchNo() + "' ,");
/* 144 */       sqlBuf.append(" type = '" + bo.getType() + "' ,");
/* 145 */       sqlBuf.append(" manufacturer = '" + bo.getManufacturer() + "' ,");
/* 146 */       sqlBuf.append(" capacity = '" + bo.getCapacity() + "' ,");
/* 147 */       sqlBuf.append(" groupnum = '" + bo.getGroupnum() + "' ,");
/* 148 */       sqlBuf.append(" batterynum = '" + bo.getBatterynum() + "' ,");
/* 149 */       sqlBuf.append(" voltage = '" + bo.getVoltage() + "' ,");
/* 150 */       sqlBuf.append(" registtime = '" + this.open.format(bo.getOpentime()) + "' ,");
/* 151 */       sqlBuf.append(" discharge = '" + bo.getDischarge() + "' ,");
/* 152 */       sqlBuf.append(" maintenance = '" + bo.getMaintenance() + "' ,");
/* 153 */       sqlBuf.append(" refreshtime = '" + this.fresh.format(new Date()) + "' ,");
/* 154 */       sqlBuf.append(" memo = '" + bo.getMemo() + "' ");
/* 155 */       sqlBuf.append(" where id = '" + bo.getId() + "' ");
/* 156 */       log.info(sqlBuf.toString());
/* 157 */       this.dbcon.execUpdate(sqlBuf.toString());
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 161 */       flag = false;
/* 162 */       e.printStackTrace();
/* 163 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 166 */       dbConClose();
/*     */     }
/* 168 */     log.info("修改--蓄电池---结束");
/* 169 */     return flag;
/*     */   }
/*     */ 
/*     */   public boolean deleteStoragebatteryBO(String strID)
/*     */   {
/* 174 */     log.info("删除--蓄电池---开始");
/* 175 */     boolean flag = true;
/*     */     try
/*     */     {
/* 178 */       dbConInit();
/* 179 */       StringBuffer sqlBuf = new StringBuffer();
/* 180 */       sqlBuf.append(" delete from  storagebattery where id='" + strID + "' ");
/* 181 */       log.info(sqlBuf.toString());
/* 182 */       this.dbcon.execUpdate(sqlBuf.toString());
/*     */     }
/*     */     catch (Exception e) {
/* 185 */       flag = false;
/* 186 */       e.printStackTrace();
/* 187 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 190 */       dbConClose();
/*     */     }
/* 192 */     log.info("删除--蓄电池---结束");
/* 193 */     return flag;
/*     */   }
/*     */ 
/*     */   public ListContentsBFO getStorageBatteryByBtsName(Map condition)
/*     */   {
/* 198 */     ListContentsBFO bfo = new ListContentsBFO();
/* 199 */     int start = Integer.parseInt(condition.get("start").toString());
/* 200 */     int limit = Integer.parseInt(condition.get("limit").toString());
/* 201 */     String strBtsName = condition.get("btsName").toString();
/* 202 */     ResultSet rs = null;
/* 203 */     List list = new ArrayList();
/*     */     try
/*     */     {
/* 206 */       dbConInit();
/* 207 */       Object objRegistBeginTime = condition.get("registBeginTime");
/* 208 */       Object objRegistEndTime = condition.get("registEndTime");
/* 209 */       if ((objRegistBeginTime == null) || ("".equalsIgnoreCase(objRegistBeginTime.toString().trim())))
/* 210 */         objRegistBeginTime = null;
/* 211 */       if ((objRegistEndTime == null) || ("".equalsIgnoreCase(objRegistEndTime.toString().trim())))
/* 212 */         objRegistEndTime = null;
/* 213 */       String strSQL = " select count(id) from storagebattery where ( btsname like '%" + strBtsName + "%' or manufacturer like '%" + strBtsName + "%' ) ";
/* 214 */       if ((objRegistBeginTime != null) && (objRegistEndTime != null))
/* 215 */         strSQL = strSQL + " and '" + objRegistEndTime.toString() + "'>= registtime and  registtime >= '" + objRegistBeginTime.toString() + "' ";
/* 216 */       else if ((objRegistBeginTime == null) && (objRegistEndTime != null))
/* 217 */         strSQL = strSQL + " and '" + objRegistEndTime.toString() + "' >= registtime ";
/* 218 */       else if ((objRegistBeginTime != null) && (objRegistEndTime == null))
/* 219 */         strSQL = strSQL + " and registtime >= '" + objRegistBeginTime.toString() + "'  ";
/* 220 */       log.info(strSQL);
/* 221 */       rs = this.dbcon.execQuery(strSQL);
/* 222 */       if (rs.next()) {
/* 223 */         bfo.setTotalSize(rs.getInt(1));
/*     */       }
/* 225 */       strSQL = " select * from storagebattery where ( btsname like '%" + strBtsName + "%' or manufacturer like '%" + strBtsName + "%') limit " + start + ", " + limit;
/* 226 */       if ((objRegistBeginTime != null) && (objRegistEndTime != null))
/* 227 */         strSQL = strSQL + " and '" + objRegistEndTime.toString() + "'>= registtime and  registtime >= '" + objRegistBeginTime.toString() + "' ";
/* 228 */       else if ((objRegistBeginTime == null) && (objRegistEndTime != null))
/* 229 */         strSQL = strSQL + " and '" + objRegistEndTime.toString() + "' >= registtime ";
/* 230 */       else if ((objRegistBeginTime != null) && (objRegistEndTime == null))
/* 231 */         strSQL = strSQL + " and registtime >= '" + objRegistBeginTime.toString() + "'  ";
/* 232 */       log.info(strSQL);
/* 233 */       rs = this.dbcon.execQuery(strSQL);
/* 234 */       while (rs.next()) {
/* 235 */         StoragebatteryBO bo = new StoragebatteryBO();
/* 236 */         bo.setId(rs.getString("id"));
/* 237 */         bo.setBtscode(rs.getString("btscode"));
/* 238 */         bo.setNo(rs.getString("no"));
/* 239 */         bo.setSwitchNo(rs.getString("switchNo"));
/* 240 */         bo.setBtsname(rs.getString("btsname"));
/* 241 */         bo.setType(rs.getString("type"));
/* 242 */         bo.setManufacturer(rs.getString("manufacturer"));
/* 243 */         bo.setCapacity(rs.getString("capacity"));
/* 244 */         bo.setGroupnum(rs.getString("groupnum"));
/* 245 */         bo.setBatterynum(rs.getString("batterynum"));
/* 246 */         bo.setVoltage(rs.getString("voltage"));
/* 247 */         bo.setOpentime(rs.getDate("registtime"));
/* 248 */         bo.setDischarge(rs.getString("discharge"));
/* 249 */         bo.setMaintenance(rs.getString("maintenance"));
/* 250 */         bo.setRefreshtime(rs.getDate("refreshtime"));
/* 251 */         bo.setMemo(rs.getString("memo"));
/* 252 */         list.add(bo);
/*     */       }
/* 254 */       bfo.setData(list.toArray());
/*     */     }
/*     */     catch (Exception e) {
/* 257 */       e.printStackTrace();
/* 258 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 261 */       dbConClose();
/*     */     }
/* 263 */     return bfo;
/*     */   }
/*     */ 
/*     */   public List export(String strBtsName, String strRegistBeginTime, String strRegistEndTime)
/*     */   {
/* 269 */     ResultSet rs = null;
/* 270 */     List list = new ArrayList();
/*     */     try
/*     */     {
/* 273 */       dbConInit();
/* 274 */       String strSQL = " select * from storagebattery where ( btsname like '%" + strBtsName + "%' or manufacturer like '%" + strBtsName + "%') ";
/* 275 */       strSQL = FormateSQL.getFormateSQL(strRegistBeginTime, strRegistEndTime, strSQL);
/* 276 */       log.info(strSQL);
/* 277 */       rs = this.dbcon.execQuery(strSQL);
/* 278 */       while (rs.next()) {
/* 279 */         StoragebatteryBO bo = new StoragebatteryBO();
/* 280 */         bo.setId(rs.getString("id"));
/* 281 */         bo.setBtscode(rs.getString("btscode"));
/* 282 */         bo.setNo(rs.getString("no"));
/* 283 */         bo.setSwitchNo(rs.getString("switchNo"));
/* 284 */         bo.setBtsname(rs.getString("btsname"));
/* 285 */         bo.setType(rs.getString("type"));
/* 286 */         bo.setManufacturer(rs.getString("manufacturer"));
/* 287 */         bo.setCapacity(rs.getString("capacity"));
/* 288 */         bo.setGroupnum(rs.getString("groupnum"));
/* 289 */         bo.setBatterynum(rs.getString("batterynum"));
/* 290 */         bo.setVoltage(rs.getString("voltage"));
/* 291 */         bo.setOpentime(rs.getDate("registtime"));
/* 292 */         bo.setDischarge(rs.getString("discharge"));
/* 293 */         bo.setMaintenance(rs.getString("maintenance"));
/* 294 */         bo.setRefreshtime(rs.getDate("refreshtime"));
/* 295 */         bo.setMemo(rs.getString("memo"));
/* 296 */         list.add(bo);
/*     */       }
/*     */     }
/*     */     catch (Exception e) {
/* 300 */       e.printStackTrace();
/* 301 */       log.error(e.getMessage());
/*     */     }
/*     */     finally {
/* 304 */       dbConClose();
/*     */     }
/* 306 */     return list;
/*     */   }
/*     */ }

/* Location:           E:\java\apache-tomcat-6.0.36\webapps\btsm\WEB-INF\classes\
 * Qualified Name:     com.yc.dao.station.StoragebatteryDAO
 * JD-Core Version:    0.6.2
 */